<template>
  <div class="page mid">
    <div class="list">
      <div
        class="list-item"
        v-for="(item, index) in menuList"
        :key="index"
        @click="itemAction(item)"
      >
        <div class="list-item-icon mid">
          <img :src="item.icon" width="28" height="32" />
        </div>
        <div class="list-item-content mid">
          <div>
            <div class="title">{{ item.name }}</div>
            <span class="exegesis" v-if="item.exegesis">{{
              '(' + item.exegesis + ')'
            }}</span>
          </div>
        </div>
        <div class="list-item-extra mid">
          <img :src="url.icon_arrow_right" width="12" height="24" />
        </div>
      </div>
    </div>
    <!-- <Rocket /> -->
  </div>
</template>

<script>
import { setCookies, getCookies } from '@/libs/auth'
import menuDict from './dict/menu'
import Rocket from './components/rocket/index.vue'
import {
  getFamilyInfo,
  getTeacherInfo,
  getWorkerInfo,
  getOutsiderInfo,
  getStudentInfo,
  getIsDeadmaster,
} from '@/api/school.js'

export default {
  data() {
    return {
      url: {
        icon_arrow_right: require('../../assets/images/school/icon_arrow_golden.png'),
      },
      userInfo: {},
      menuList: menuDict.enter,
      dictData: {},
      dialogShow: false,
      dialogTitle: '',
      dialogState: '',
    }
  },
  components: { Rocket },
  computed: {},
  watch: {},
  async mounted() {
    // 置空居住人孩子类型 -> 重置title
    localStorage.setItem('childrenType', '')
    // 授权登录
    let { key, card_no, name, mobile } = this.$route.query
    // 用户信息处理
    if (card_no && name && mobile) {
      if (!key) {
        let getkey = getCookies('token')
        if (!getkey) {
          this.$toast('登录失败')
          return
        } else {
          key = getkey
        }
      }
      // 设置1天token有效期
      this.$store.dispatch('user/changeToken', key)
      setCookies('token', key, 43200)
      this.$store.dispatch('user/changeUserInfo', {
        card_no: card_no,
        name: name,
        mobile: mobile,
      })

      this.userInfo = this.$store.state.user.userInfo
    } else {
      // this.$store.dispatch('user/changeUserInfo', {})
      // const returnUrl = encodeURIComponent(window.location.href)
      // window.location.href =
      //   'https://dalianyqschool.lngov.top' +
      //   '/api/ac/dalianyqschool/qstbMobileService/redirectToDaLian'
    }
    // +'?returnUrl=' +returnUrl
    // if (!this.$route.query.card_no) {
    //   this.$toast('缺少参数')
    //   return
    // }
    // if (this.$store.state.user.userInfo.card_no) {
    //   this.userInfo = this.$store.state.user.userInfo
    // } else {
    //   this.$store.dispatch('user/changeUserInfo', {})
    //   this.$store.dispatch('user/changeUserInfo', this.$route.query)
    // }
  },
  methods: {
    async itemAction(item) {
      if (!this.userInfo.card_no) {
        this.$toast('请在辽事通实名认证')
        return
      }
      switch (item.id) {
        case 'studentHealth':
          // this.$router.push({
          //   path: '/school/children-enter',
          //   query: {},
          // })
          // 判断是否注册过
          const familyInfo = await getFamilyInfo({
            card_no: this.userInfo.card_no,
          })
          if (familyInfo.data.errcode == 0) {
            if (this.$common.xeUtils.isEmpty(familyInfo.data.data)) {
              this.$router.push({
                path: '/school/family',
                query: {
                  isFirst: 1,
                },
              })
            } else {
              this.$router.push({
                path: '/school/family-list',
                query: { parent_id: familyInfo.data.data.parent_id },
              })
            }
          }
          break
        case 'teacherHealth':
          const teacherInfo = await getTeacherInfo({
            card_no: this.userInfo.card_no,
          })
          if (
            teacherInfo.data.data &&
            JSON.stringify(teacherInfo.data.data) !== '{}'
          ) {
            this.$router.push({
              path: '/school/healthTeacher',
              query: {
                type: 'teacher',
                teacher_id: teacherInfo.data.data.id,
                school_name: teacherInfo.data.data.school_name,
              },
            })
            // this.$toast('您已完成注册，填报功能暂未开放')
          } else {
            this.$router.push({
              path: '/school/teacherRegister',
              query: {},
            })
          }
          break
        case 'headTeacher':
          const bzrInfo = await getIsDeadmaster({
            card_no: this.userInfo.card_no,
          })
          if (bzrInfo.data.errcode == 0) {
            if (bzrInfo.data.data) {
              this.$router.push({
                path: '/school/teacher-enter',
                query: {
                  card_no: this.userInfo.card_no,
                },
              })
            } else {
              this.$toast('仅班主任用户可以访问')
            }
          } else {
            this.$toast(bzrInfo.data.errmsg)
          }
          break
        case 'workerHealth':
          const workerInfo = await getWorkerInfo({
            card_no: this.userInfo.card_no,
          })
          if (workerInfo.data.data) {
            this.$router.push({
              path: '/school/healthWorker',
              query: {
                type: 'worker',
                workers_id: workerInfo.data.data.id,
              },
            })
            // this.$toast('您已完成注册，填报功能暂未开放')
          } else {
            this.$router.push({
              path: '/school/workerRegister',
              query: {},
            })
          }
          break
        case 'visit':
          // const outsiderInfo = await getOutsiderInfo({
          //   card_no: this.userInfo.card_no,
          // })
          // if (outsiderInfo.data.data) {
          //   this.$router.push({
          //     path: '/school/outsider-history',
          //     query: { page_type: 'outsider', card_no: this.userInfo.card_no },
          //   })
          // } else {
          //   this.$toast('仅外来人员用户可以访问')
          // }
          this.$toast('功能暂未开放')
          break
        case 'exam':
          // this.$router.push({
          //   path: '/school/exam-list',
          //   query: { page_type: 'exam', card_no: this.userInfo.card_no },
          // })
          this.$toast('功能暂未开放')
          break
        case 'exit':
          // const exitStudentInfo = await getStudentInfo({
          //   card_no: this.userInfo.card_no,
          // })
          // if (exitStudentInfo.data.data) {
          //   this.$router.push({
          //     path: '/school/exit-list',
          //     query: { page_type: 'exit', card_no: this.userInfo.card_no },
          //   })
          // } else {
          //   this.$toast('仅学生用户可以访问')
          // }
          this.$toast('功能暂未开放')
          break
        case 'return':
          // const returnStudentInfo = await getStudentInfo({
          //   card_no: this.userInfo.card_no,
          // })
          // if (returnStudentInfo.data.data) {
          //   this.$router.push({
          //     path: '/school/return-list',
          //     query: { page_type: 'return', card_no: this.userInfo.card_no },
          //   })
          // } else {
          //   this.$toast('仅学生用户可以访问')
          // }
          this.$toast('功能暂未开放')
          break
        default:
          this.$toast('暂无权限')
          break
      }
    },
  },
}
</script>

<style lang="less" scoped>
.page {
  background: url('../../assets/images/school/bg_enter_new.png') no-repeat;
  background-size: contain;
  padding: 30px;
  width: 100%;
  height: auto;
  box-sizing: border-box;
  color: black;
  overflow: auto;

  .dialog {
    height: 800px;

    // 内容
    /deep/ .van-dialog__content {
      overflow-y: auto;
      height: 100%;
    }

    // 操作栏
    /deep/ .van-dialog__footer {
      transform: translate3d(0, 0, 0);
      width: 100%;
      position: absolute;
      bottom: 0;
    }

    // 对话框内容
    &-container {
      min-height: 200px;
      color: #000;
      padding: 10px 10px 120px;
    }
  }

  .list {
    margin-bottom: 100px;
    margin-top: 90%;
    //background-color: #ffffff;
    min-height: 600px;
    width: 100%;
    border-radius: 20px;
    box-sizing: border-box;

    & > :not(:last-child) {
      margin-bottom: 20px;
    }

    .list-item {
      min-height: 80px;
      display: flex;
      box-sizing: border-box;
      justify-content: space-between;
      align-items: center;
      background-image: url('../../assets/images/school/bar_golden.png');
      background-repeat: no-repeat;
      background-size: 100% 100%;
      padding: 30px 30px;
      border-radius: 5px;

      &-content {
        width: 75%;
        text-align: left;
        padding: 0px 8px;

        .title {
          font-weight: 500;
          font-size: 22px;
          line-height: 48px;
          text-align: left;
          color: #d58913;
        }

        .exegesis {
          text-align: left;
          color: #d58913;
          font-weight: 500;
          font-size: 18px;
        }

        .desc {
          font-size: 24px;
        }
      }

      &-extra {
        font-weight: bold;
      }
    }
  }
}
</style>
